// #![allow(unused_must_use)]
#[allow(unused_must_use)]
#[allow(dead_code)]

#[macro_use]
extern crate actix_web;
#[macro_use]
extern crate log;
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_derives;
#[macro_use]
extern crate diesel_migrations;

#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;

extern crate env_logger;
extern crate dotenv;

extern crate regex;


use actix_cors::Cors;
use actix_web::{App, web::{FormConfig, JsonConfig}, HttpServer, middleware::{Logger, NormalizePath}};
use crate::data::ShareData;
use dotenv::dotenv;
use std::env;
use crate::pool::database_pool_establish;


pub mod data;
pub mod pool;
pub mod schema;
pub mod models;
pub mod srv;
pub mod api;
pub mod db_type;
pub mod utils;


#[actix_rt::main]
async fn main() {
    dotenv().ok();
    let database_url = env::var("DATABASE_URL")
        .expect(".env 文件中 DATABASE_URL 没有设置");

    let data = ShareData::new(database_pool_establish(&database_url));
    HttpServer::new(move || App::new()
        .app_data(data.clone())
        .data(data.clone())
        .data(JsonConfig::default().limit(256_000))
        .data(FormConfig::default().limit(256_000))
        .wrap(Logger::default())
        .wrap(Cors::default())
        .wrap(NormalizePath {})
        .configure(api::routes)
    )
        .bind("127.0.0.1:8000")
        .unwrap()
        .run()
        .await
        .unwrap()
}
